package net.huashitong.supervision.insideDuCha.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.ObjectUtils;
import net.huashitong.supervision.insideDuCha.entity.InsideCycleEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class InsideCycleDao extends StringDao<InsideCycleEntity> {


    /**
     * 取出所有有效的
     * @return
     */
    public List<InsideCycleEntity> getListCycleRemind(){
            GenericQuery query = createQuery("obj");
            query.append(" and obj.valids= '1' ");
            return query.listResult();
        }

        public List<InsideCycleEntity> getCycles(String taskUserId,String taskSubid,String taskMainId,String userId)
        {
            GenericQuery query = createQuery("obj");
            if(ObjectUtils.isNotBlank(userId))
            {

                query.append(" and obj.userId=:userId").setParam("userId",userId);
            }
            if(ObjectUtils.isNotBlank(taskMainId))
            {
                query.append(" and obj.mainTaskId=:mainTaskId").setParam("mainTaskId",taskMainId);

            }
            if(ObjectUtils.isNotBlank(taskSubid))
            {

                query.append(" and obj.subTaskId=:subTaskId").setParam("subTaskId",taskSubid);
            }
            if(ObjectUtils.isNotBlank(taskUserId))
            {

                query.append(" and obj.userTaskId=:userTaskId").setParam("userTaskId",taskUserId);
            }


            query.append(" and obj.valids= '1' ");

            return query.listResult();
        }

}
